import myutil.*;
class node1 {
	int data;
	node1 next;
	public node1(int d,node1 n){
		this.data = d;
		this.next = n;
		}
}

public class LinkedList {

	node1 head = null;
	node1 reverse_head = null;
	
	public void insertNode(int d){
		node1 temp_head = head;
		node1 n = new node1(d,null);
		if(temp_head == null) {
			head = n;
		} else {
			while (temp_head.next!=null){
				temp_head = temp_head.next;
			}
			temp_head.next = n;
			return;
		}
	}
	
	public void printList(node1 head){
		node1 temp_head = head;
		while(temp_head != null){
			System.out.print(temp_head.data+" ->");
			temp_head = temp_head.next;
		}
	}
	
	public void reverseList () {
		node1 double_next_node = head;
		node1 next_node;
		node1 start = head;
		while (double_next_node != null){
			next_node = double_next_node;
			double_next_node = next_node.next;
			reverse_head = next_node;
			if(start == head)start.next= null;
			next_node.next = start;
			start = next_node;
		}
		
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		LinkedList l = new LinkedList();
		int i = MyInput.readInt();
		l.insertNode(i);
		l.insertNode(2);
		l.insertNode(3);
		l.insertNode(4);
		l.insertNode(5);
		l.printList(l.head);
        l.reverseList();
        l.printList(l.reverse_head);
	}

}
